package com.learn.english.service.impl;

import com.learn.english.service.ICodeService;
import jakarta.servlet.http.HttpSession;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * 验证码服务实现类
 */
@Service
public class CodeServiceImpl implements ICodeService {

    @Override
    public boolean verifyCode(String code, HttpSession session) {
        // 从session中获取验证码
        String sessionCode = (String) session.getAttribute("captcha");
        if (sessionCode == null) {
            return false;
        }
        // 比较验证码（忽略大小写）
        return Objects.equals(sessionCode.toLowerCase(), code.toLowerCase());
    }
}